﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Brain
{
    public class MenuEntry_Sprite : MenuEntry
    {
        public Sprite Sprite;

        public object Tag;

        public bool UpdateSpriteBounds = true;

        public MenuEntry_Sprite(Sprite sprite)
        {
            this.Sprite = sprite;
        }
        public MenuEntry_Sprite(Sprite sprite, MenuSystem system, int X, int Y)
        {
            system.AddEntry(this, X, Y);
            this.Sprite = sprite;
        }

        public override void Update()
        {
            base.Update();

            if (UpdateSpriteBounds)
            {
                Sprite.UpdateBoundsRectangle();
            }
            Sprite.Update();
            Sprite.Draw();

            Vector2 mousePos = Engine.Instance.InputManager.GetMousePosition();
            if (Engine.Instance.CameraManager.Camera2D != null)
            {
                Matrix world = Matrix.Invert(Engine.Instance.CameraManager.Camera2D.World);
                mousePos = Vector2.Transform(mousePos, world);
            }
            /*
            if (Engine.Instance.RenderManager2D.CustomResMatrix != null)
            {
                mousePos = Vector2.Transform(mousePos, Matrix.Invert(Engine.Instance.RenderManager2D.CustomResMatrix.Value));
            }*/

            Rectangle mouseRect = new Rectangle((int)mousePos.X, (int)mousePos.Y, 1, 1);
            Vector2 mouseDif = Engine.Instance.InputManager.GetMouseDifference();
            int add = (int)(mouseDif.X + mouseDif.Y);
            if (Sprite.BoundsRectangle.Contains(mouseRect))
            {
                if (add != 0)
                {
                    this.System.SetSelected(X, Y);
                }
                if (Engine.Instance.InputManager.IsMouseLeftClick())
                {
                    this.Selected();
                }
            }   
        }
    }
}
